﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<InternshipManagement.Helpers.PaginatedList<InternshipManagement.Models.Announcement>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Announcements
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script src="<%: Url.Content("~/Scripts/jquery.validate.min.js") %>" type="text/javascript"></script>
    <script src="<%: Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js") %>"
        type="text/javascript"></script>
    <% 
    ViewBag.AnnouncementOp = 0;
    Html.RenderPartial("AnnouncementMenu"); 
    %>
    <% if (Model.Count == 0)
       {%>
       <span>No Announcement Found.</span>
    <%} %>
    <div id="announcementsaccordion">
        <% foreach (var item in Model)
           { %>
            <h3 id="announcement<%=item.ID %>">
            <a href="#">
                <span style="display:none" class="announcementID"><%=item.ID%></span>
                <span><%= item.Title %></span>
                <span class="newmail <%= ViewBag.Unread.Contains(item.ID) ? "" : "read" %>"></span>
                <span style="float:right;"><%=item.SentDate.Value.ToString("dd-MM-yyyyy")%></span>
            </a>
            </h3>
        <div>
            <span style="float:left;width:100%"><%= item.Message %></span>
            <% if (item.Document != null)
               { %>
            <span style="margin-top:20px;float:left">Attached Document: <a href="<%=item.Document.Path%>"><%=item.Document.Name%></a></span>
            <%} %>
        </div>
        <% } %>
    </div>
    <script type="text/javascript">
        jQuery(document).ready(function () {

            var accOpts = {
                changestart: function (e, ui) {
                    if (!ui.newHeader.find('.newmail').hasClass('read')) {
                        var ID = ui.newHeader.find('.announcementID').html();
                        jQuery.ajax({
                            type: 'POST',
                            url: '/Announcement/MarkAsRead',
                            data: $.toJSON({ id: ID }),
                            contentType: 'application/json; charset=utf-8',
                            success: function (data) {
                                ui.newHeader.find('.newmail').addClass('read');
                            },
                            statusCode: {
                                404: function () {
                                    alert('page not found');
                                }
                            }
                        });
                    }
                },
                collapsible: true,
                active: false
            };
            $("#announcementsaccordion").accordion(accOpts);
        });

    </script>
</asp:Content>
